<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增地图管理')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-esmap-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">地图ID：</label>
                <div class="col-sm-8">
                    <input name="mapId" class="form-control" type="text">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">上传地图：</label>
                <div class="col-sm-8">
                    <input id="filePath" name="filePath" class="form-control" type="file" multiple webkitdirectory>
                </div>
            </div>

            <div class="form-group">    
                <label class="col-sm-3 control-label">建筑token：</label>
                <div class="col-sm-8">
                    <input name="token" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">地图数据位置：</label>
                <div class="col-sm-8">
                    <input name="mapDataUrl" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">地图主题位置：</label>
                <div class="col-sm-8">
                    <input name="mapThemeUrl" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">样式ID：</label>
                <div class="col-sm-8">
                    <input name="themeId" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">中心点坐标：</label>
                <div class="col-sm-8">
                    <input name="centerCoordinate" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "system/esmap"
        $("#form-esmap-add").validate({
            focusCleanup: true
        });

        // function submitHandler() {
        //     if ($.validate.form()) {
        //         $.operate.save(prefix + "/add", $('#form-esmap-add').serialize());
        //     }
        // }
        function submitHandler() {
            if ($.validate.form()) {
                uploadFile();
            }
        }

        function uploadFile() {
            var formData = new FormData();
            if ($('#filePath')[0].files[0] == null) {
                $.modal.alertWarning("请先选择文件路径");
                return false;
            }
            // formData.append('fileName', $("#fileName").val());
            formData.append('file', $('#filePath')[0].files);
            $.ajax({
                url: prefix + "/add",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function(result) {
                    $.operate.successCallback(result);
                }
            });
        }
    </script>
</body>

</html>